<template>
  <!-- 
        <m_glimg
          :show="val.yituliu"
          @upshow="val.yituliu = $event"
          cdnid="6504fc35186c533c03340641"
          title="一图流"
        >
          <template #box>
            <n-button @click="val.yituliu = true">一图流</n-button>
          </template>
        </m_glimg>
  -->
  <!-- 获取props传递过来的show 变量 -->
  <n-modal v-model:show="show">
    <n-card
      class="work_card"
      preset="card"
      @close="show = false"
      closable
      aria-modal="true"
    >
      <template #header>{{ title }}</template>
      <div>
        <img :src="`${cfg.cdn2}?file=${img}`" style="width: 100%" />
      </div>
    </n-card>
  </n-modal>
  <slot name="box"> </slot>
</template>
<script>
//2024/07/20 猫燐
import { cfg } from "@/cfg/cfg.js";

export default {
  props: {
    cdnid: {},
    title: {},
    show: {},
  },
  emits: ["upshow"],
  setup(props, { emit }) {
    let show = ref(props.show);
    let loading = false;
    let img = ref();

    watch(
      () => props.show,
      (newVal, oldVal) => {
        show.value = newVal;
      }
    );
    watch(
      () => show.value,
      async (newVal, oldVal) => {
        emit("upshow", newVal);
        if (loading == false) {
          loading = true;
          let res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "v2/get",
              t2: "introduction/getgl_name",
              id: props.cdnid,
            },
          });
          img.value = res.data.data;
        }
      }
    );

    return {
      cfg,
      props,
      show,
      img,
    };
  },
};
</script>
